package com.learnyou.server.xingzuo.common.util;

import com.google.common.collect.Lists;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;


public class StringUtil extends StringUtils {


    public static final String SEPARATE = ",";

    public static final String SEMICOLON = ";";



    public static List<String> explode(String heads) {
        String[] split = StringUtils.split(heads, ",");
        if (split == null) {
            return Lists.newArrayListWithCapacity(0);
        }
        List<String> result = Lists.newArrayList();
        result.addAll(Arrays.asList(split));
        return result;
    }


    public static String convert2Str(Collection collection, String cut) {
        if (CollectionUtils.isEmpty(collection)) {
            return StringUtils.EMPTY;
        }
        return join(collection, cut);
    }


    public static List<Integer> explodeInt(String heads) {
        String[] split = StringUtils.split(heads, ",");
        if (split == null) {
            return Lists.newArrayListWithCapacity(0);
        }
        List<Integer> integers = Lists.newArrayList();
        for (String one : split) {
            integers.add(NumberUtils.toInt(one));
        }
        return integers;
    }

    public static List<Long> explodeLong(String heads) {
        String[] split = StringUtils.split(heads, ",");
        if (split == null) {
            return Lists.newArrayListWithCapacity(0);
        }
        List<Long> longs = Lists.newArrayList();
        for (String one : split) {
            longs.add(NumberUtils.toLong(one));
        }
        return longs;
    }



}
